
package com.kilomob.grady.model;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

import com.kilomob.grady.codec.JProtocolHeader;

/**
 * 
 * 心跳包
 * 
 * @author zhouzhixiang  
 * @date 2017年4月6日
 * @since 1.0
 */
public class Heartbeats {

    private static final ByteBuf HEARTBEAT_BUF;

    static {
        ByteBuf buf = Unpooled.buffer(JProtocolHeader.HEAD_LENGTH);
        buf.writeShort(JProtocolHeader.MAGIC);
        buf.writeByte(JProtocolHeader.HEARTBEAT); // 心跳包这里可忽略高地址的4位序列化/反序列化标志
        buf.writeByte(0);
        buf.writeLong(0);
        buf.writeInt(0);
        HEARTBEAT_BUF = Unpooled.unreleasableBuffer(buf).asReadOnly();
    }

    /**
     * Returns the shared heartbeat content.
     */
    public static ByteBuf heartbeatContent() {
        return HEARTBEAT_BUF.duplicate();
    }
}
